const doc: any = document.documentElement || document

// 是否全屏
export const isFullscreen = (): Boolean => {
  const _docu: any = document
  const isFullscreen =
    _docu.isFullScreen ||
    _docu.mozIsFullScreen ||
    _docu.webkitIsFullScreen ||
    _docu.msIsFullScreen || false
  return isFullscreen
}

// 退出全屏
export const exitFullscreen = (): void => {
  const _docu: any = document
  const fn = _docu.exitFullscreen
    || _docu.mozCancelFullScreen
    || _docu.webkitCancelFullScreen
    || _docu.msCancelFullScreen
  fn.call(_docu)
}

// 全屏
export const requestFullscreen = (el?: HTMLElement | null): void => {
  const _el = el || doc
  const fn = _el.requestFullscreen
    || _el.mozRequestFullScreen
    || _el.webkitRequestFullScreen
    || _el.msRequestFullscreen
  fn.call(_el)
}

// 切换全屏
export const swithFullscreen = (el?: HTMLElement | null): void => {
  if (isFullscreen()) {
    exitFullscreen()
  } else {
    requestFullscreen(el)
  }
}
